/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Id: FileLogCollector.java 377 2007-02-08 23:27:47Z jacek.kolezynski $
 */
package logmatcher.collectors;

import org.apache.commons.lang.UnhandledException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;


/**
 * Class represents collector taking messages from file. 
 *
 * @version $Revision: 377 $
*/
public class FileLogCollector extends CollectorSkeleton {
    //~ Static fields/initializers -------------------------------------------------------------------------------------

    /** Class logger. */
    private static final Log LOGGER = LogFactory.getLog(FileLogCollector.class);

    //~ Instance fields ------------------------------------------------------------------------------------------------

    /** Reader. */
    private BufferedReader in;

    /** Filename. */
    private String filename;

    //~ Constructors ---------------------------------------------------------------------------------------------------

/**
     * Creates a new ServerSocketLogCollector object.
     *
     */
    public FileLogCollector() {
        super();
    }

    //~ Methods --------------------------------------------------------------------------------------------------------

    /**
     * {@inheritDoc}
     */
    protected Object readMessage() throws IOException, UnhandledException {
        return in.readLine();
    }


    /**
     * {@inheritDoc}
     */
    public void start() throws IOException {
        in = new BufferedReader(new FileReader(filename));
        super.start();
    }


    /**
     * {@inheritDoc}
     */
    public void stop() throws IOException {
        super.stop();
        in.close();
    }


    /**
     * DOCUMENT ME!
     *
     * @return the filename
     */
    public String getFilename() {
        return filename;
    }


    /**
     * DOCUMENT ME!
     *
     * @param filename the filename to set
     */
    public void setFilename(String filename) {
        this.filename = filename;
    }
    
}
